package com.hstcs.creator;

import com.badlogic.ashley.core.Entity;
import com.badlogic.gdx.graphics.g2d.Animation;
import com.badlogic.gdx.graphics.g2d.Animation.PlayMode;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Vector2;
import com.hstcs.assets.Assets;
import com.hstcs.assets.Common;
import com.hstcs.assets.Config;
import com.hstcs.assets.FileName;
import com.hstcs.components.AnimationComponent;
import com.hstcs.components.BulletComponent;
import com.hstcs.components.MovementComponent;
import com.hstcs.components.StateComponent;
import com.hstcs.components.TextureComponent;
import com.hstcs.components.TransformComponent;
import com.hstcs.game.God;

public class BulletCreator implements EntityCreator {
	static public Vector2 pos =new Vector2();
	static public void create(TransformComponent  stc){
		Entity entity = new Entity();
		BulletComponent bc = new BulletComponent();
		TextureComponent tc = new TextureComponent();
		MovementComponent mc = new MovementComponent();
		AnimationComponent ac = new  AnimationComponent();
		StateComponent sc = new StateComponent();
		
		TransformComponent  btc = new TransformComponent();
		btc.rotation = stc.rotation -180;
		sc.set(BulletComponent._MOVE);
		ac.animations.put(BulletComponent._MOVE, new Animation(0.4f, 
				Assets.getRegionArray(FileName._BULLET_1, 3, 4, 6, 8), PlayMode.LOOP));
		btc.pos.set(stc.pos.x +MathUtils.sinDeg(btc.rotation + 90)*10,
				stc.pos.y - MathUtils.cosDeg(btc.rotation + 90)*10, Common.DEPTH_BULLENT);
		bc.hurt = Common.BULLET_HURT;
		
		mc.velocity.set(Config.BULLET_V * MathUtils.cosDeg(btc.rotation + 90), 
				Config.BULLET_V * MathUtils.sinDeg(btc.rotation + 90));
		entity.add(bc);
		entity.add(tc);
		entity.add(mc);
		entity.add(ac);
		entity.add(btc);
		entity.add(sc);
		God.instance.engine.addEntity(entity);
	}
}
